const connection = require("../db")
const md5Password = require("../utils/md5")

class myServer {
  getuserinfo(username) {
    const statement = "select * from user where username = ?"
    return connection.execute(statement, [username])
  }
  updatauserinfo(id, nickname, email) {
    const statement = " UPDATE `user` SET nickname =?,email=? WHERE id = ?"
    return connection.execute(statement, [nickname, email, id])
  }
  checkpassword(username, password) {
    const statement = "select * from user where username = ? and password = ?"
    return connection.execute(statement, [username, md5Password(password)])
  }
  updatauserpassword(username, password) {
    const statement = " UPDATE `user` SET password =? WHERE username = ?"
    return connection.execute(statement, [md5Password(password), username])
  }
  updatauseravatar(username, avatar) {
    const statement = " UPDATE `user` SET user_pic =? WHERE username = ?"
    return connection.execute(statement, [avatar, username])
  }
}

module.exports = new myServer()
